package com.block.account.service.impl;

import com.block.account.model.dto.EntryAccountDTO;
import com.block.db.entity.AccountInfo;
import com.block.db.entity.AccountInfoHis;
import com.block.db.entity.AccountItemChannleHis;
import com.block.db.mapper.AccountInfoHisMapper;
import com.block.account.service.IAccountInfoHisService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

/**
 * <p>
 * 总账户流水表 服务实现类
 * </p>
 *
 * @author 
 * @since 2023-02-02
 */
@Service
public class AccountInfoHisServiceImpl extends ServiceImpl<AccountInfoHisMapper, AccountInfoHis> implements IAccountInfoHisService {

    @Override
    public boolean saveAccountHisInfo(AccountInfo accountInfo, EntryAccountDTO entryAccountDTO) {
        AccountInfoHis accountInfoHis = new AccountInfoHis();
        accountInfoHis.setDateInfo(LocalDate.now().toString());
        accountInfoHis.setAccountId(Integer.valueOf(accountInfo.getId()));
        accountInfoHis.setAccountName(accountInfo.getName());
        accountInfoHis.setAccountNo(accountInfo.getAccountNo());
        accountInfoHis.setAccountUser(accountInfo.getAccountUser());
        accountInfoHis.setAccountType(accountInfo.getType());
        accountInfoHis.setActionType(entryAccountDTO.getActionType());

        accountInfoHis.setChangeAmount(entryAccountDTO.getChangeAmount());
        accountInfoHis.setOriginAmount(entryAccountDTO.getOriginAmount());
        accountInfoHis.setCurrentAmount(entryAccountDTO.getCurrentAmount());

        accountInfoHis.setItemAccountId(entryAccountDTO.getItemAccountId());
        accountInfoHis.setItemAccountType(entryAccountDTO.getItemAccountType());
        accountInfoHis.setItemAccountKey(entryAccountDTO.getItemAccountKey());
        accountInfoHis.setItemAccountName(entryAccountDTO.getItemAccountName());

        accountInfoHis.setDataId(entryAccountDTO.getExtData());

        accountInfoHis.setOperatorId(entryAccountDTO.getOperatorId());
        accountInfoHis.setOperatorName(entryAccountDTO.getOperatorName());

        boolean saveRes = this.save(accountInfoHis);

        return saveRes;
    }
}
